﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using CoiffeurProject.Utils;
using CoiffeurProject.Screens;

namespace CoiffeurProject.UserControls
{
    internal class LettersDashSlider
    {
        Grid main_container;
        Image thumb;
        DashArrow right, left;

        int[] offsets = new int[] { 108, 173, 237, 303, 368, 431, 495, 562, 624, 681, 743, 807, 873, 942, 
            1011, 1077, 1143, 1209, 1273, 1336, 1401, 1467, 1536, 1604, 1668, 1732 };

        int actual_position = 0;

        internal LettersDashSlider(int col, int row, int colspan, int rowspan)
        {
            main_container = new Grid()
            {
                Width = 1920,
                Height = 79,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top
            };

            Grid.SetColumn(main_container, col);
            Grid.SetRow(main_container, row);
            if (colspan > 0) Grid.SetColumnSpan(main_container, colspan);
            if (rowspan > 0) Grid.SetRowSpan(main_container, rowspan);

            left = new DashArrow(DashArrowVerse.Left, new Thickness(26, 16, 0, 0), 0, 0,
                delegate(object sender, RoutedEventArgs e) {
                    if (actual_position > 0)
                    {
                        actual_position -= 1;
                        thumb.Margin = new Thickness(offsets[actual_position], 19, 0, 0);
                    }
                });

            main_container.Children.Add(left.MainContainer);

            right = new DashArrow(DashArrowVerse.Right, new Thickness(1847, 16, 0, 0), 0, 0,
                delegate(object sender, RoutedEventArgs e) {
                    if (actual_position < 26)
                    {
                        actual_position += 1;
                        thumb.Margin = new Thickness(offsets[actual_position], 19, 0, 0);
                    }
                });

            main_container.Children.Add(right.MainContainer);

            thumb = new Image()
            {
                Source = new BitmapImage(new Uri(ImagesPath.DashThumb)),
                Height = 45,
                Width = 77,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Stretch = Stretch.Fill,
                Margin = new Thickness(108, 19, 0, 0)
            };

            main_container.Children.Add(thumb);
        }

        public Grid MainContainer { get { return main_container; } }

        public Button LeftArrow { get { return left.MainContainer; } }

        public Button RightArrow { get { return right.MainContainer; } }

        public int CurrentThumbPosition { get { return actual_position; } }

        public char SelectedLetter { get { return (char)((int)'a' + actual_position); } }
    }
}
